/*
 *
 *  * Copyright (c) 2020-2021, Lykan (jiashuomeng@gmail.com).
 *  * <p>
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  * <p>
 *  *     http://www.apache.org/licenses/LICENSE-2.0
 *  * <p>
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 *
 */
package cn.kstry.framework.test.mono.service;

import cn.kstry.framework.core.annotation.ReqTaskParam;
import cn.kstry.framework.core.annotation.TaskComponent;
import cn.kstry.framework.core.annotation.TaskService;
import cn.kstry.framework.test.mono.bo.SayInfoRequest;
import org.junit.Assert;
import reactor.core.publisher.Mono;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author lykan
 */
@SuppressWarnings("unused")
@TaskComponent(name = "mono-service", scanSuper = false)
public class MonoSuccessServiceDemotion extends MonoSuccessService {

    @TaskService(name = "say_empty_info3_demotion", ability = "ability")
    public Mono<Void> sayEmptyInfo3Demotion(@ReqTaskParam(reqSelf = true) SayInfoRequest request,
                                            @ReqTaskParam int a, @ReqTaskParam Boolean b, @ReqTaskParam String c) {
        System.out.println("say_empty_info3_demotion...");
        Assert.assertTrue(a - 345 >= 0);
        Assert.assertEquals(true, b);
        Assert.assertEquals("Mono测试", c);
        return Mono.fromFuture(CompletableFuture.runAsync(() -> {
            try {
                TimeUnit.MILLISECONDS.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, Executors.newFixedThreadPool(1)));
    }

    @TaskService(name = "say_empty_info4_demotion")
    public Mono<Void> sayEmptyInfo4Demotion(@ReqTaskParam(reqSelf = true) SayInfoRequest request,
                                            @ReqTaskParam int a, @ReqTaskParam Boolean b, @ReqTaskParam String c) {
        System.out.println("say_empty_info4_demotion...");
        Assert.assertTrue(a - 345 >= 0);
        Assert.assertEquals(true, b);
        Assert.assertEquals("Mono测试", c);
        throw new RuntimeException("测试非严格模式");
    }

    @TaskService(name = "say_info2_demotion")
    public Mono<SayInfoRequest> sayInfo2Demotion(@ReqTaskParam(reqSelf = true) SayInfoRequest request,
                                                 @ReqTaskParam int a, @ReqTaskParam Boolean b, @ReqTaskParam String c) {
        Assert.assertTrue(a - 345 >= 0);
        Assert.assertEquals(true, b);
        Assert.assertEquals("Mono测试", c);
        System.out.println("say_info2_demotion...");
        request.setD(100);
        return Mono.just(request);
    }
}
